Page({

    data: {
        userInfo: {},
        isLogin: '', //登陆状态
        videoStar: 0,
        foodStar: 0
    },
    gotoLogin() {
        wx.navigateTo({
            url: '../login/index',
        })
    },
    toArticleList() {
        wx.navigateTo({
            url: '../collectArticle/index',
        })
    },
    toFoodList() {
        wx.navigateTo({
            url: '../collectFoods/index'
        })
    },

    onUserInfo() {

    },
    gotoCustomPage(event) {
        const {code} = event.currentTarget.dataset
        switch (code) {
            case 'bmi':
                wx.navigateTo({
                    url: '../BMI/index',
                })
                break;
            case  'about-me':
                wx.navigateTo({
                    url: '../about-me/index',
                })
                break;
        }
    },
    async onShow() {
        //tab-bar判断
        if (typeof this.getTabBar === 'function' &&
            this.getTabBar()) {
            this.getTabBar().setData({
                current: 2
            })
        }
        const logged = wx.getStorageSync('logged')
        const userInfo = wx.getStorageSync('userInfo')

        //判断是否登录
        if (logged) {
            this.setData({
                userInfo,
                isLogin: true
            })
        } else {
            this.setData({
                isLogin: false
            })
        }
    },

})